package cn.tedu;

import java.sql.*;

public class Demo03 {
    public static void main(String[] args) throws SQLException {
        Connection conn=
                DriverManager.getConnection(
                        "jdbc:mysql://localhost:3310/empdb?characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false","root","123456");
        Statement s=conn.createStatement();
        //插入数据
        //s.executeUpdate("insert into emp(name) values ('Tom')");
        //修改数据
        //s.executeUpdate("update emp set name='Jerry' where name='Tom'");
        //删除数据
        //s.executeUpdate("delete from emp where name='Jerry'");
        //查询数据
        ResultSet rs=s.executeQuery("select name,sal,job from emp");
        //遍历查询结果集对象
        while (rs.next()){
            //通过查询到的字段名获取数据
            String name=rs.getString("name");
            double sal=rs.getDouble("sal");
            String job=rs.getString("job");
            System.out.println(name+":"+sal+":"+job);
        }
        //关闭资源
        conn.close();


    }
}
